package com.naizhuai.ui.testunit;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.gson.Gson;
import com.naizhuai.R;
import com.naizhuai.ui.BaseActivity;
import com.naizhuai.ui.entity.QRCodeMsgBean;
import com.naizhuai.ui.entity.QRCodeScanBean;
import com.naizhuai.util.HideNumberUtils;
import com.naizhuai.util.IntentUtils;
import com.naizhuai.util.QRCodeUtil;
import com.naizhuai.util.RxBus;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;

/**
 * 1/生成加入公司的二维码
 * 2/生成加入某个公司的部门的二维码
 * 3/识别二维码进行添加
 */
public class ManageTestFunctionActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.create_join_company_code)
    Button createCompany;
    @BindView(R.id.create_join_person_code)
    Button createDepartment;
    @BindView(R.id.join_code)
    Button jointCode;

    private QRCodeMsgBean bean;

    private static final int CODE=200;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bean = new QRCodeMsgBean();
    }

    @OnClick({R.id.create_join_company_code, R.id.create_join_person_code, R.id.join_code})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.create_join_company_code:
                bean.setScanType(QRCodeMsgBean.DEPARTMENT_JOIN_TYPE);
                QRCodeMsgBean.GroupMsg group = new QRCodeMsgBean.GroupMsg();
                group.setCompanyId("1");
                group.setCompanyName("东莞老司机一条龙公司");
                group.setDepartChargeThumbStr("http://inte-image.oss-cn-beijing.aliyuncs.com/ad/20180413/40ba3c5cf183da9d9122f0b5373d286f.jpg");
                group.setDepartName("一波油推部");
                group.setDepartId("3");
                bean.setGroup(group);
                IntentUtils.startActivityWithObject(QRCodeMsgBean.QRCode_MSG_KEY, bean, this, ManageTestCreateQRCodeActivity.class);
                break;
            case R.id.create_join_person_code:
                bean.setScanType(QRCodeMsgBean.USER_JOIN_TYPE);
                QRCodeMsgBean.PersonMsg person = new QRCodeMsgBean.PersonMsg();
                person.setUserId("616540685");
                person.setUserName("张三");
                person.setUserPhoneNumber(HideNumberUtils.hidePhoneNumber("13546857458"));
                person.setUserThumb("http://inte-image.oss-cn-beijing.aliyuncs.com/ad/20180413/40ba3c5cf183da9d9122f0b5373d286f.jpg");
                bean.setPerson(person);
                IntentUtils.startActivityWithObject(QRCodeMsgBean.QRCode_MSG_KEY, bean, this, ManageTestCreateQRCodeActivity.class);
                break;
            case R.id.join_code:
                IntentUtils.startActivityForResult(this, ManageTestScanQRCodeActivity.class,CODE);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(data==null)
            return;
        switch (requestCode){
            case CODE:
                QRCodeScanBean bean= (QRCodeScanBean) data.getSerializableExtra(QRCodeScanBean.SCAN_DATA_KEY);
                if(bean!=null){
                    Toast.makeText(this, new Gson().toJson(bean), Toast.LENGTH_SHORT).show();
                }else
                    shortToast("扫描错误");
                break;
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.test_activity_qrcode_layout;
    }

}
